/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>

using namespace std;
struct PNode
{
    char name[11];
    char gender;
    char ID[11];
    int grade;
} temp_person,boy,girl;
void initP()
{
    boy.grade=101;
    girl.grade=-1;
}
int main_1036()
{
    initP();
    int N;
    scanf("%d",&N);
    for (int i=0;i<N ;++i )
    {
        scanf("%s %c %s %d",temp_person.name,&temp_person.gender,temp_person.ID,&temp_person.grade);
        if (temp_person.gender=='M')
        {
            if (temp_person.grade<boy.grade)
            {
                boy=temp_person;
            }
        }
        else
        {
            if (temp_person.grade>girl.grade)
            {
                girl=temp_person;
            }
        }
    }
    if (girl.grade==-1)
    {
        printf("Absent\n");
    }
    else
    {
        printf("%s %s\n",girl.name,girl.ID);
    }
    if (boy.grade==101)
    {
        printf("Absent\n");
    }else
    {
        printf("%s %s\n",boy.name,boy.ID);
    }
    if (girl.grade==-1||boy.grade==101)
    {
        printf("NA");
    }
    else
    {
        printf("%d",girl.grade-boy.grade);
    }
	return 0;
}
